home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #11 / Amiga Plus CD - 2004 - No. 11.iso / AmiSoft / Comm / www / tidy_os4.lha / tidy / src / streamio.h < prev    next >
C/C++ Source or Header  |  2004-07-25  |  5KB  |  219 lines

  1. #ifndef __STREAMIO_H__
  2. #define __STREAMIO_H__
  3.  
  4. /* streamio.h -- handles character stream I/O
  5.  
  6.   (c) 1998-2003 (W3C) MIT, ERCIM, Keio University
  7.   See tidy.h for the copyright notice.
  8.  
  9.   CVS Info :
  10.  
  11.     $Author: hoehrmann $ 
  12.     $Date: 2004/03/07 14:38:47 $ 
  13.     $Revision: 1.12 $ 
  14.  
  15.   Wrapper around Tidy input source and output sink
  16.   that calls appropriate interfaces, and applies 
  17.   necessary char encoding transformations: to/from
  18.   ISO-10646 and/or UTF-8.
  19.  
  20. */
  21.  
  22. #include "forward.h"
  23. #include "buffio.h"
  24. #include "fileio.h"
  25.  
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. typedef enum
  31. {
  32.   FileIO,
  33.   BufferIO,
  34.   UserIO
  35. } IOType;
  36.  
  37. /************************
  38. ** Source
  39. ************************/
  40.  
  41. #define CHARBUF_SIZE 5
  42.  
  43. /* non-raw input is cleaned up*/
  44. struct _StreamIn
  45. {
  46.     int    state;     /* FSM for ISO2022 */
  47.     Bool   pushed;
  48.     tchar* charbuf;
  49.     uint   bufpos;
  50.     uint   bufsize;
  51.     int    tabs;
  52.     int    lastcol;
  53.     int    curcol;
  54.     int    curline;
  55.     int    encoding;
  56.     IOType iotype;
  57.  
  58.     TidyInputSource source;
  59.  
  60. #ifdef TIDY_WIN32_MLANG_SUPPORT
  61.     ulong  mlang;
  62. #endif
  63.  
  64. #ifdef TIDY_STORE_ORIGINAL_TEXT
  65.     tmbstr otextbuf;
  66.     size_t otextsize;
  67.     uint   otextlen;
  68. #endif
  69.  
  70.     /* Pointer back to document for error reporting */
  71.     TidyDocImpl* doc;
  72. };
  73.  
  74. void freeStreamIn(StreamIn* in);
  75.  
  76. StreamIn* FileInput( TidyDocImpl* doc, FILE* fp, int encoding );
  77. StreamIn* BufferInput( TidyDocImpl* doc, TidyBuffer* content, int encoding );
  78. StreamIn* UserInput( TidyDocImpl* doc, TidyInputSource* source, int encoding );
  79.  
  80. int       ReadBOMEncoding(StreamIn *in);
  81. uint      ReadChar( StreamIn* in );
  82. void      UngetChar( uint c, StreamIn* in );
  83. uint      PopChar( StreamIn *in );
  84. Bool      IsEOF( StreamIn* in );
  85.  
  86.  
  87. /************************
  88. ** Sink
  89. ************************/
  90.  
  91. struct _StreamOut
  92. {
  93.     int   encoding;
  94.     int   state;     /* for ISO 2022 */
  95.     uint  nl;
  96.  
  97. #ifdef TIDY_WIN32_MLANG_SUPPORT
  98.     ulong mlang;
  99. #endif
  100.  
  101.     IOType iotype;
  102.     TidyOutputSink sink;
  103. };
  104.  
  105. StreamOut* FileOutput( FILE* fp, int encoding, uint newln );
  106. StreamOut* BufferOutput( TidyBuffer* buf, int encoding, uint newln );
  107. StreamOut* UserOutput( TidyOutputSink* sink, int encoding, uint newln );
  108.  
  109. StreamOut* StdErrOutput(void);
  110. StreamOut* StdOutOutput(void);
  111. void       ReleaseStreamOut( StreamOut* out );
  112.  
  113. void WriteChar( uint c, StreamOut* out );
  114. void outBOM( StreamOut *out );
  115.  
  116. ctmbstr GetEncodingNameFromTidyId(uint id);
  117.  
  118. /************************
  119. ** Misc
  120. ************************/
  121.  
  122. /* character encodings
  123. */
  124. #define RAW         0
  125. #define ASCII       1
  126. #define LATIN0      2
  127. #define LATIN1      3
  128. #define UTF8        4
  129. #define ISO2022     5
  130. #define MACROMAN    6
  131. #define WIN1252     7
  132. #define IBM858      8
  133.  
  134. #if SUPPORT_UTF16_ENCODINGS
  135. #define UTF16LE     9
  136. #define UTF16BE     10
  137. #define UTF16       11
  138. #endif
  139.  
  140. /* Note that Big5 and SHIFTJIS are not converted to ISO 10646 codepoints
  141. ** (i.e., to Unicode) before being recoded into UTF-8. This may be
  142. ** confusing: usually UTF-8 implies ISO10646 codepoints.
  143. */
  144. #if SUPPORT_ASIAN_ENCODINGS
  145. #if SUPPORT_UTF16_ENCODINGS
  146. #define BIG5        12
  147. #define SHIFTJIS    13
  148. #else
  149. #define BIG5        9
  150. #define SHIFTJIS    10
  151. #endif
  152. #endif
  153.  
  154. #ifdef TIDY_WIN32_MLANG_SUPPORT
  155. /* hack: windows code page numbers start at 37 */
  156. #define WIN32MLANG  36
  157. #endif
  158.  
  159. /* states for ISO 2022
  160.  
  161.  A document in ISO-2022 based encoding uses some ESC sequences called
  162.  "designator" to switch character sets. The designators defined and
  163.  used in ISO-2022-JP are:
  164.  
  165.     "ESC" + "(" + ?     for ISO646 variants
  166.  
  167.     "ESC" + "$" + ?     and
  168.     "ESC" + "$" + "(" + ?   for multibyte character sets
  169. */
  170. #define FSM_ASCII    0
  171. #define FSM_ESC      1
  172. #define FSM_ESCD     2
  173. #define FSM_ESCDP    3
  174. #define FSM_ESCP     4
  175. #define FSM_NONASCII 5
  176.  
  177.  
  178. /* char encoding used when replacing illegal SGML chars,
  179. ** regardless of specified encoding.  Set at compile time
  180. ** to either Windows or Mac.
  181. */
  182. extern const int ReplacementCharEncoding;
  183.  
  184. /* Function for conversion from Windows-1252 to Unicode */
  185. uint DecodeWin1252(uint c);
  186.  
  187. /* Function to convert from MacRoman to Unicode */
  188. uint DecodeMacRoman(uint c);
  189.  
  190. /* Function for conversion from OS/2-850 to Unicode */
  191. uint DecodeIbm850(uint c);
  192.  
  193. /* Function for conversion from Latin0 to Unicode */
  194. uint DecodeLatin0(uint c);
  195.  
  196. /* Function to convert from Symbol Font chars to Unicode */
  197. uint DecodeSymbolFont(uint c);
  198. #ifdef __cplusplus
  199. }
  200. #endif
  201.  
  202.  
  203. /* Use numeric constants as opposed to escape chars (\r, \n)
  204. ** to avoid conflict Mac compilers that may re-define these.
  205. */
  206. #define CR    0xD
  207. #define LF    0xA
  208.  
  209. #if   defined(MAC_OS_CLASSIC)
  210. #define DEFAULT_NL_CONFIG TidyCR
  211. #elif defined(_WIN32) || defined(OS2_OS)
  212. #define DEFAULT_NL_CONFIG TidyCRLF
  213. #else
  214. #define DEFAULT_NL_CONFIG TidyLF
  215. #endif
  216.  
  217.  
  218. #endif /* __STREAMIO_H__ */
  219.